package com.jsoft.dao.impl;

import com.jsoft.dao.MyVoucherDao;
import com.jsoft.entity.MyVoucher;
import com.jsoft.util.DAO;

import java.util.List;

/**
 * @author zhangxuehan
 * @email 2302630156@qq.com
 * @date 2023/2/20
 */
public class MyVoucherDaoImpl extends DAO<MyVoucher> implements MyVoucherDao {
    /**
     * 查询所有凭证
     * @return
     * @throws Exception
     */
    @Override
    public List listAll(String id,int start,int page,String sqlVoucher) throws Exception {
        String sql = "select id,no,amount,enterpriseId,enterpriseName,institutyName," +
                "openTime,expiryTime,address,source,status" +
                " FROM myvoucher" + " WHERE enterpriseId = ?" + sqlVoucher + " limit ?,?";
        return getForList(sql,id,start,page);
    }

    /**
     * 总记录数
     * @return
     * @throws Exception
     */
    @Override
    public Long count(String id,String sqlVoucher) throws Exception {
        String sql = "SELECT count(1)" +
                " FROM myvoucher" +
                " where enterpriseId = ?" + sqlVoucher;
        return getForValue(sql,id);
    }

    /**
     * 开单企业下拉选框
     * @return
     * @throws Exception
     */
    @Override
    public List listOpen(String id) throws Exception {
        String sql = "select name FROM enterprise where id not in (?)";
        return getForList(sql,id);
    }

    @Override
    public List findId(int id) throws Exception {
        String sql = "select id from myvoucher where enterpriseId = ?";
        return getForList(sql,id);
    }

    @Override
    public List findIdAndStatus(int id) throws Exception {
        String sql = "SELECT v.id,v.NO,v.amount,v.enterprise_id enterpriseId,e.`name` enterpriseName,i.NAME institutyName,v.open_time openTime,v.expiry_Time expiryTime,v.uplink_address address,v.source,v.`STATUS` FROM voucher v,enterprise e,instituty i WHERE v.open_enterprise_id = e.id AND v.instituty_id = i.id AND v.enterprise_id = ? AND v.`STATUS` = 'A'";
        return getForList(sql, id);
    }
}
